package com.my.code.innerclass;

public class OuterClass {

    private String out = "out field";
    private static String OUT_FIELD = "out static field";

    public class InnerClass {
        public void say() {
            System.out.println("innerClass get outerClass.out = " + out);
            System.out.println("innerClass get outerClass.OUT_FIELD = " + OUT_FIELD);
        }
    }

    public static class InnerStaticClass {
        public void say() {
            //System.out.println("innerStaticClass get outerClass.out = " + out);//报错，不可访问非静态成员变量
            System.out.println("innerStaticClass get outerClass.OUT_FIELD = " + OUT_FIELD);

        }
    }

    public static void main(String[] args) {
        OuterClass outerClass = new OuterClass();
        InnerClass innerClass = outerClass.new InnerClass();//普通内部类不能脱离外部类实例而存在
        InnerStaticClass innerStaticClass = new InnerStaticClass();//静态内部类可以脱离外部类实例单独使用

        innerClass.say();
        innerStaticClass.say();

    }

}
